package top.xierongsheng.user.validate.impl;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.springframework.beans.factory.annotation.Autowired;
import top.xierongsheng.user.model.SysRole;
import top.xierongsheng.user.service.IRoleService;
import top.xierongsheng.user.validate.ValidRole;



public class RoleValidator implements ConstraintValidator<ValidRole, String> {

    @Autowired
    private IRoleService roleService;

    @Override
    public void initialize(ValidRole constraintAnnotation) {
    }

    @Override
    public boolean isValid(String param, ConstraintValidatorContext constraintValidatorContext) {
        SysRole sysRole = roleService.getById(param);
        if (sysRole == null) {
            return false;
        }
        return true;
    }
}
